package pong.devices;

import pong.general.R;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;



public class InputBox extends Dialog {

  private String result = null;

  private EditText keyEdit = null;

  private TextView textMessage = null;

  private static final int MAXIMUM_DIALOG_WIDTH = 650;

  public InputBox(Context _context, String _title, String _message) {
    super(_context);
 
    
    setContentView(R.layout.input_box);
    

    setTitle(_title);
    textMessage = ((TextView) findViewById(R.id.inputText));
    keyEdit = ((EditText) findViewById(R.id.inputEditText));

    textMessage.setText(_message);

    adjustSize();

  }

  private void adjustSize() {
    DeviceInfoHelper.reviewScreenProperties();
    int width = (int) (DeviceInfoHelper.getScreenWidth() * 0.92);
    // int height = DeviceInfoHelper.getScreenHeight();

    if (width > MAXIMUM_DIALOG_WIDTH)
      width = MAXIMUM_DIALOG_WIDTH;

    Dialog d = this;

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = width;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    d.getWindow().setAttributes(lp);

  }

  public void onBackPressed() {
    cancel();
  }

  public InputBox setOkListener(View.OnClickListener _onOk) {
    findViewById(R.id.okButton).setOnClickListener(_onOk);
    return this;
  }

  public InputBox setCancelListener(View.OnClickListener _onCancel) {
    findViewById(R.id.cancelButton).setOnClickListener(_onCancel);
    return this;
  }

  public String getResult() {
    return keyEdit.getText().toString();
  }

  public EditText getKeyEdit() {
    return keyEdit;
  }

}
